package com.umeox.ota.data.repository;

import android.app.Application;

import com.umeox.ota.data.repository.base.RepositoryComponent;

import java.io.File;

/**
 * @author fighter_lee
 * @date 2018/7/26
 */
public class RepositoryComponentImpl implements RepositoryComponent {

    private final Builder mBuilder;

    public RepositoryComponentImpl(Builder builder) {
        this.mBuilder = builder;
    }

    @Override
    public IRepositoryManager repositoryManager() {
        return new RepositoryManager(mBuilder.application, mBuilder.repositoryConfigModule.provideCacheFactory(), mBuilder.repositoryConfigModule.provideRoomConfiguration());
    }

    @Override
    public File cacheFile() {
        return mBuilder.repositoryConfigModule.provideCacheFile();
    }

    public static Builder builder() {
        return new Builder();
    }

    public static final class Builder {
        private RepositoryConfigModule repositoryConfigModule;
        private Application application;

        public Builder setRepositoryConfigModule(RepositoryConfigModule configModule) {
            this.repositoryConfigModule = configModule;
            return this;
        }

        public Builder setApplication(Application application) {
            this.application = application;
            return this;
        }

        public RepositoryComponent build() {
            return new RepositoryComponentImpl(this);
        }
    }
}
